package edu.ncsu.csc.ip.routing.dv.udp;

import java.net.SocketException;

import edu.ncsu.csc.ip.routing.dv.Node;
import edu.ncsu.csc.ip.routing.dv.RouteEntity;
import edu.ncsu.csc.ip.routing.dv.RouterLocal;

/**
 * Class <code>Router</code>
 * 
 * Simulation of Routers that interact with each other thru UDP. 
 * 
 * @author Moin Ayazifar <mayazif@ncsu.edu>
 * @author Steven Elliott <sdelliot@ncsu.edu>
 * 
 */

public class RouterRemote extends RouterLocal {

	public static final int MAX_PACKET_SIZE = 1400;
	public static final String IP_PORT_DELIM = ":";
	
	int port;

	public RouterRemote(Node node, int port) {
		super(node);
		this.port = port;
	}

	public void start() throws Exception {
		//Start the sender thread
		new ClientThread(this).start();
	}

	public void initialize() throws SocketException {
		localNode.distanceVector.put(localNode,
				new RouteEntity(localNode, 0.0d));
		// Initialize local DV and prepare it to send to neighbors
		for (RouteEntity re : localNode.neighborsMap.values())
			localNode.distanceVector.put(re.nextNode, re);
		//Start the receiver thread
		new ServerThread(this).start();
	}

}
